package com.mobdev.notepadgdocs;

import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.net.Uri;
import android.util.AttributeSet;
import android.widget.EditText;

import com.mobdev.notepad.shared.ui.AbstractNoteEditor;
import com.mobdev.notepadgdocs.sync.SyncActivity;

/**
 * A generic activity for editing a note in a database.  This can be used
 * either to simply view a note {@link Intent#ACTION_VIEW}, view and edit a note
 * {@link Intent#ACTION_EDIT}, or create a new note {@link Intent#ACTION_INSERT}.
 */
public class NoteEditor extends AbstractNoteEditor {
    /**
     * A custom EditText that draws lines between each line of text that is displayed.
     */
    public static class LinedEditText extends EditText {
        private Rect mRect;
        private Paint mPaint;

        // we need this constructor for LayoutInflater
        public LinedEditText(Context context, AttributeSet attrs) {
            super(context, attrs);

            mRect = new Rect();
            mPaint = new Paint();
            mPaint.setStyle(Paint.Style.STROKE);
            //mPaint.setColor(0x800000FF);
            mPaint.setColor(0xFF804000);
        }

        @Override
        protected void onDraw(Canvas canvas) {
            int count = getLineCount();
            Rect r = mRect;
            Paint paint = mPaint;

            for (int i = 0; i < count; i++) {
                int baseline = getLineBounds(i, r);
                canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
            }

            super.onDraw(canvas);
        }
    }

	@Override
	protected void init() {
		// Set the layout for this activity.  You can find it in res/layout/note_editor.xml
        setContentView(R.layout.note_editor);


        // The text view for our note, identified by its ID in the XML file.
        mText = (EditText) findViewById(R.id.note);

	}

	@Override
	protected int getSyncMenuIconId()
	{
		return R.drawable.sync_48;
	}

	@Override
	protected void doEditTitle(Uri mUri)
	{
		startActivity(new Intent(this, TitleEditor.class).setData(mUri));
	}

	@Override
	protected void doSync()
	{
		// Launch activity to sync notes with helipad
		startActivity(new Intent(this, SyncActivity.class));
	}

}
